#!/usr/bin/env bash


# ----------------------------------------------------------------------
# Filename	:  sr0
# Version	:  1.0
# Date		:  2022/02/22
# Author	:  Lz
# Email		:  liuzuo@kylinos.com.cn 
# History	:     
#            	   Version 1.0, 2022/02/22
# Function	:  光驱设备限制
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------


# 测试主题
Title_Env_LTFLIB="安全加固(接入类) - 光驱设备限制"


## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	if [ "Z${Sr0_Access_SSRFlag}" == "Z" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "未定义变量 Sr0_Access_SSRFlag"
	elif [ "Z${Sr0_Access_SSRFlag}" != "ZTrue" -a "Z${Sr0_Access_SSRFlag}" != "ZFalse" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "Sr0_Access_SSRFlag 无效的参数: ${Sr0_Access_SSRFlag}"
	fi

        return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1

        return $TPASS
}

# 文件内容测试
testcase_1(){
        local flag_str="KERNEL==\"sr0\", ENV{UDISKS_IGNORE}=\"1\""
        local false_str="${flag_str}"
        local true_str="${flag_str}"

        # 查看文件中配置
        local file_conf="/etc/udev/rules.d/90-ssr-external.rules"
        local cmd="cat ${file_conf}"

        if [ "Z${Sr0_Access_SSRFlag}" == "ZTrue" ];then
                eval ${cmd} | grep -E "${flag_str}"
                eval ${cmd} | grep -Eq "${true_str}"
                CommRetParse_LTFLIB "${cmd}查询,要求不存在${true_str}" "False" "yes"
        else
                eval ${cmd} | grep -E "${flag_str}"
                eval ${cmd} | grep -Eq "${true_str}"
                CommRetParse_LTFLIB "${cmd}查询,要求存在${true_str}" "False"
        fi
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
